home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / hard / hack / i2clib40.lha / i2clib40 / src / LED.c < prev    next >
C/C++ Source or Header  |  1997-09-06  |  3KB  |  95 lines

  1. /*========================================================================*
  2.  |  File: LED.c                                        Date: 17 Aug 1997  |
  3.  *------------------------------------------------------------------------*
  4.  |   Subroutines for controlling an SAA 1064 LED-display on the I²C-Bus.  |
  5.  |                                                                        |
  6.  *========================================================================*/
  7.  
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <exec/types.h>
  11. #include <proto/dos.h>
  12. #include <proto/i2c.h>
  13. #include "LED.h"
  14.  
  15.  
  16. #define SAA1064 0x70    /* may be jumpered as 0x72, 0x74, 0x76, too */
  17. #define CRAP    0x49    /* bit pattern for undefined characters */
  18.  
  19. /* bit numbers in the LED digits:
  20.     ___
  21.   5| 0 |1
  22.    |___|
  23.   4| 6 |2
  24.    |___|.
  25.      3   7
  26. */
  27.  
  28. UBYTE ubaLedCode[96] =          /* bit patterns for ' ' through '~' */
  29. {
  30.   0x00, 0x82, 0x22, CRAP, CRAP, CRAP, CRAP, 0x20,       /*   !"#$%&'  */
  31.   0x39, 0x0F, CRAP, 0x70, 0x80, 0x40, 0x80, 0x52,       /*  ()*+,-./  */
  32.   0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07,       /*  01234567  */
  33.   0x7F, 0x6F, CRAP, CRAP, 0x58, 0x48, 0x4C, 0x53,       /*  89:;<=>?  */
  34.   CRAP, 0x77, 0x7F, 0x39, 0x3F, 0x79, 0x71, 0x3D,       /*  @ABCDEFG  */
  35.   0x76, 0x06, 0x0E, 0x75, 0x38, 0x79, 0x37, 0x3F,       /*  HIJKLMNO  */
  36.   0x73, 0x67, 0x77, 0x6D, 0x31, 0x3E, 0x3E, 0x4F,       /*  PQRSTUVW  */
  37.   0x76, 0x72, 0x5B, 0x39, 0x64, 0x0F, 0x23, 0x08,       /*  XYZ[\]^_  */
  38.   0x02, 0x5F, 0x7C, 0x58, 0x5E, 0x7B, 0x71, 0x6F,       /*  `abcdefg  */
  39.   0x74, 0x04, 0x0C, 0x75, 0x06, 0x79, 0x54, 0x5C,       /*  hijklmno  */
  40.   0x73, 0x67, 0x50, 0x6D, 0x70, 0x1C, 0x1C, 0x4F,       /*  pqrstuvw  */
  41.   0x76, 0x66, 0x5B, 0x39, 0x30, 0x0F, 0x01, CRAP        /*  xyz{|}~   */
  42. };
  43.  
  44.  
  45. ULONG SendLed( STRPTR strMsg )
  46. /* returns 0 if OK, else the i2c.lib error code */
  47. {
  48.   BYTE baBuf[6] = { 0, 0x17, 0, 0, 0, 0 };
  49.   WORD wIdx;
  50.   ULONG ulResult;
  51.                                                   
  52.   for( wIdx = 2; wIdx<6 && *strMsg; wIdx++, strMsg++ )
  53.     {
  54.       if( *strMsg<' ' || *strMsg>'~' )
  55.         baBuf[wIdx] = CRAP;
  56.       else
  57.         baBuf[wIdx] = ubaLedCode[*strMsg - ' '];
  58.       if( strMsg[1] == '.' )    /* join '.' to the preceding character */
  59.         {
  60.           baBuf[wIdx] |= 0x80;
  61.           strMsg++;
  62.         }
  63.     }
  64.   ulResult = SendI2C( SAA1064, 6, baBuf );
  65.   if( ulResult & 0x0f )
  66.     return 0;
  67.   else
  68.     return ulResult;
  69. }
  70.  
  71.  
  72. ULONG LedScroll( STRPTR strMsg, WORD wTiming )
  73.   ULONG ulResult;
  74.  
  75.   ulResult = SendLed( strMsg );
  76.   while( strlen( strMsg ) > 4 && ulResult == 0 )
  77.     {
  78.       ulResult = SendLed( ++strMsg );
  79.       Delay( wTiming );
  80.     } 
  81.   return ulResult;
  82. }
  83.  
  84.  
  85. ULONG LedNumber( LONG lNumber )
  86. {                      
  87.   char caBuf[10];
  88.  
  89.   sprintf( caBuf, "%4ld", lNumber );
  90.   return LedScroll( caBuf, 10 );
  91. }
  92.  
  93.  
  94.